package com.qzsoft.zhjd.server.common.utils;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DataCollectDataConverter implements Converter {

    @Override
    public Object convert(Class type, Object value) {
        String dateStr = (String)value;
        if (StringUtils.isNotBlank(dateStr)){
            SimpleDateFormat spdt;
            if (dateStr.indexOf(":")>0){
                spdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            }else{
                spdt = new SimpleDateFormat("yyyy-MM-dd");
            }
            try {
                Date date = spdt.parse(dateStr);
                return date;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
